@extends('layout.page')
@section('title','群体管理 - 添加')
@section('stylesheet')
    <link href="/css/custom.css" rel="stylesheet">
@endsection

@section('static-page')
    <div class="col-sm-12">
        <div class="ibox float-e-margins">
            <div class="ibox-title">
                <h5>群体管理 <small>添加</small></h5>
            </div>
            <div class="ibox-content">
                <form method="post" action="/ceb/community/doCreate" class="form-horizontal">
                    {{csrf_field()}}
                    <input type="hidden" name="info[cid]" value=""/>
                    <div class="form-group  ">
                        <label class="col-sm-2 control-label">群体名称：</label>
                        <div class="col-sm-6">
                            <div class="row">
                                <div class="col-md-8">
                                    <input type="text"  name="info[name]" value=""
                                           placeholder="群体名称" class="form-control screen-validata-notempty" data-value="name">
                                    <span class="help-block m-b-none">{{$errors->first('info.name')}}</span>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="hr-line-dashed"></div>
                    <div class="form-group ">
                        <label class="col-sm-2 control-label">群体描述：</label>
                        <div class="col-sm-10">
                            <div class="row">
                                <div class="col-md-7">
                                    <input type="text" name="info[description]" value=""
                                           placeholder="群体描述" class="form-control" data-value="description">
                                    <span class="help-block m-b-none">{{$errors->first('info.description')}}</span>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="ibox-title">
                        <h5>筛选项<small></small></h5>
                    </div>
                    <div class="form-group ">
                        <label class="col-sm-2 control-label">首投：</label>
                        <div class="col-sm-4">
                            <div class="row">
                                <div class="col-md-4 m-b-xs">
                                    <select  name="screenOption[first_invest]" class="form-control input-s-sm inline">
                                        @foreach($screenOption['havebuy'] as $key => $val)
                                            <option  value="{{ $val['id'] }}">{{ $val['name']}}</option>
                                        @endforeach
                                    </select>
                                </div>
                            </div>
                        </div>
                        <label class="col-sm-2 control-label">性别：</label>
                        <div class="col-sm-4">
                            <div class="row">
                                <div class="col-md-4 m-b-xs">
                                    <select name="screenOption[sex]" class="form-control input-s-sm inline">
                                        @foreach($screenOption['sex'] as $sexKey => $sexVal)
                                            <option  value="{{ $sexVal['id'] }}">{{$sexVal['name']}}</option>
                                        @endforeach
                                    </select>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="hr-line-dashed"></div>
                    <div class="form-group  ">
                        <label class="col-sm-2 control-label">年龄大于>=：</label>
                        <div class="col-sm-4">
                            <div class="row">
                                <div class="col-md-4 m-b-xs">
                                    <input type="text" name="screenOption[age_lower]" value=""
                                           placeholder="年龄" class="form-control screen-validata" data-value="age_lower">
                                    <span class="help-block m-b-none"></span>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="hr-line-dashed"></div>

                    <div class="form-group ">
                        <label class="col-sm-2 control-label">最小单笔年化投资额(元)>=：</label>
                        <div class="col-sm-4">
                            <div class="row">
                                <div class="col-md-4 m-b-xs">
                                    <input type="text" name="screenOption[single_annual_amount]" value=""
                                           placeholder="最小单笔年化投资额" class="form-control screen-validata" data-value="single_annual_amount">
                                    <span class="help-block m-b-none"></span>
                                </div>
                            </div>
                        </div>


                        <label class="col-sm-2 control-label">最小单笔投资额(元)>=：</label>
                        <div class="col-sm-4">
                            <div class="row">
                                <div class="col-md-4">
                                    <input type="text" name="screenOption[single_investment_amount]" value=""
                                           placeholder="最小单笔投资额" class="form-control screen-validata" data-value="single_investment_amount">
                                    <span class="help-block m-b-none">{{$errors->first('info.label')}}</span>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="hr-line-dashed"></div>
                    <div class="form-group ">
                        <label class="col-sm-2 control-label">累计年化投资额(元)>=：</label>
                        <div class="col-sm-4">
                            <div class="row">
                                <div class="col-md-4 m-b-xs">
                                    <input type="text" name="screenOption[total_annual_amount]" value=""
                                           placeholder="累计年化投资额" class="form-control screen-validata" data-value="total_annual_amount">
                                    <span class="help-block m-b-none"></span>
                                </div>
                            </div>
                        </div>
                        <label class="col-sm-2 control-label">累计投资额(元)>=：</label>
                        <div class="col-sm-4">
                            <div class="row">
                                <div class="col-md-4">
                                    <input type="text" name="screenOption[total_investment_amount]" value=""
                                           placeholder="累计投资额" class="form-control screen-validata" data-value="total_investment_amount">
                                    <span class="help-block m-b-none"></span>
                                </div>
                            </div>
                        </div>
                    </div>
           <!--         <div class="form-group ">
                        <label class="col-sm-2 control-label">注册时间开始>=：</label>
                        <div class="col-sm-4">
                            <div class="row">
                                <div class="col-md-4 m-b-xs">
                                    <input placeholder="开始" readonly name="screenOption[start_time]" value="" class="form-control layer-date" id="start">
                                    <span class="help-block m-b-none"></span>
                                </div>
                            </div>
                        </div>
                        <label class="col-sm-2 control-label">注册时间开始结束<：</label>
                        <div class="col-sm-4">
                            <div class="row">
                                <div class="col-md-4">
                                    <input placeholder="结束" readonly name="screenOption[end_time]" value="" class="form-control layer-date" id="end">
                                    <span class="help-block m-b-none"></span>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="form-group ">
                        <label class="col-sm-2 control-label">是否实名制：</label>
                        <div class="col-sm-4">
                            <div class="row">
                                <div class="col-md-4 m-b-xs">
                                    <select name="screenOption[is_varify]" class="form-control input-s-sm inline">

                                        @foreach($screenOption['IS_VARIFY'] as $varifyKey => $varifyVal)
                                            <option  value="{{ $varifyVal['id'] }}">{{$varifyVal['name']}}</option>
                                        @endforeach


                                    </select>
                                    <span class="help-block m-b-none"></span>
                                </div>
                            </div>
                        </div>
                        <label class="col-sm-2 control-label">是否绑卡：</label>
                        <div class="col-sm-4">
                            <div class="row">
                                <div class="col-md-4">
                                    <select name="screenOption[is_card]" class="form-control input-s-sm inline">
                                        @foreach($screenOption['IS_CARD'] as $cardKey => $cardVal)
                                            <option  value="{{ $cardVal['id'] }}">{{$cardVal['name']}}</option>
                                        @endforeach
                                    </select>
                                    <span class="help-block m-b-none"></span>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="form-group ">
                        <label class="col-sm-2 control-label">累计订单笔数>=：</label>
                        <div class="col-sm-4">
                            <div class="row">
                                <div class="col-md-4 m-b-xs">
                                    <input type="text" name="screenOption[orders_count]" value=""
                                           placeholder="累计订单笔数" class="form-control screen-validata" data-value="total_investment_amou"
                                    <span class="help-block m-b-none"></span>
                                </div>
                            </div>
                        </div>

                    </div>   -->
                    <div class="hr-line-dashed"></div>
                    <div class="form-group ">
                        <label class="col-sm-2 control-label">近30天成功投资数>=：</label>
                        <div class="col-sm-4">
                            <div class="row">
                                <div class="col-md-4 m-b-xs">
                                    <input type="text" name="screenOption[investment_in_30_days]" value=""
                                           placeholder="近30天成功投资数" class="form-control screen-validata" data-value="investment_in_30_days">
                                    <span class="help-block m-b-none"></span>
                                </div>
                            </div>
                        </div>

                    </div>
                    <div class="hr-line-dashed"></div>
                    <div class="form-group ">
                        <div class="col-sm-12">
                            <div class="col-sm-1" id="loading" style="display: none">
                                <div class="sk-spinner sk-spinner-wave">
                                    <div class="sk-rect1"></div>
                                    <div class="sk-rect2"></div>
                                    <div class="sk-rect3"></div>
                                    <div class="sk-rect4"></div>
                                    <div class="sk-rect5"></div>
                                </div>
                            </div>
                            <label class="col-sm-3" id="res-count"></label>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-sm-4 col-sm-offset-2">
                            <button class="btn btn-primary" type="button" id="btn-search">搜索</button>
                            <button class="btn btn-primary" type="button" id="btn-save">保存内容</button>
                            <a href="javascript:void(0);" onclick="window.history.back()">
                                <button class="btn btn-white" type="button">取消</button>
                            </a>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
@endsection

@section('javascript')
    <script>
        $(document).ready(function () {
            var ex_int = /^\d+$/;
            function screenValidata() {
                var screenOption={};
                var flag=false;
                $(".screen-validata").each(function () {
                    if($(this).val().length>0 && !ex_int.test($(this).val())){
                        $(this).next().html('值必须为整数');
                        $(this).parents('.form-group').addClass('has-error');
                        flag= true;
                        return false;
                    }
                    var key = $(this).data('value');
                    screenOption[key] = $(this).val();
                });
                if(flag){
                    return false;
                }
                return screenOption;
            }


            $("#btn-save").click(function () {
                var doc_name = $("input[name='info[name]']");
                if(doc_name.val().length == 0){
                    doc_name.next().html('值不能为空');
                    doc_name.parents('.form-group').addClass("has-error");
                    return false;
                }

                doc_name.next().html('');
                doc_name.parents('.form-group').removeClass("has-error");
                if(!screenValidata()){
                    return false;
                }
                if(($("#start").val()=="")&&( $("#end").val()!==""))
                {
                    alert('开始结束 必须同时填写');
                    return false;
                }
                if(($("#start").val()!=="")&&( $("#end").val()==""))
                {
                    alert('开始结束 必须同时填写');
                    return false;
                }
                $('form').submit();
            });

            $("#btn-search").click(function () {
                var conditions = screenValidata();
                if(!conditions){
                    return false;
                }
                $.ajax({
                    type:'get',
                    url:'/ceb/community/getCountByconditions',
                    dataType:'json',
                    data:$('form').serialize(),
                    beforeSend:function () {
                        $("#loading").show();
                    },
                    success:function (data) {
                        $("#res-count").html("共"+data['data']['count']+"人符合条件");
                    },
                    complete:function () {
                        $("#loading").hide();
                    }

                });
            });


        });
        var start = {
            elem: '#start',
            format: 'YYYY-MM-DD',
            /*  min: laydate.now(),*/ //设定最小日期为当前日期
            max: '2099-06-16 23:59:59', //最大日期
            istime: true,
            istoday: false,
            choose: function (datas) {
                end.min = datas; //开始日选好后，重置结束日的最小日期
                end.start = datas //将结束日的初始值设定为开始日
            }
        };
        var end = {
            elem: '#end',
            format: 'YYYY-MM-DD',
            /*  min: laydate.now(),*/
            max: '2099-06-16 23:59:59',
            istime: true,
            istoday: false,
            choose: function (datas) {
                start.max = datas; //结束日选好后，重置开始日的最大日期
            }
        };
        $("#start").click(function () {
            laydate(start);
        });
        $("#end").click(function () {
            laydate(end);
        });
    </script>
@endsection
